a11y: Set an accessible role for GtkSearchEntry
authorMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 22:15:01 +0000 (18:15 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 22:16:37 +0000 (18:16 -0400)
Use the searchbox accessible role for GtkSearchEntry.
And set properties as appropriate.

Update the documentation and add a test.

docs/reference/gtk/section-accessibility.md
gtk/gtkenums.h
gtk/gtksearchentry.c
testsuite/a11y/meson.build
testsuite/a11y/searchentry.c [new file with mode: 0644]

index 702e6b01d66ea1709d4723225dd2731e852d1eaa..30c6f9e42b552d3239be95574b056c624168a94d 100644 (file)
@@ -56,6 +56,7 @@ Each role name is part of the #GtkAccessibleRole enumeration.
 | `PROGRESS_BAR` | An element that display progress | #GtkProgressBar |
 | `RADIO` | A checkable input in a group of radio roles | #GtkRadioButton |
 | `SCROLLBAR` | A graphical object controlling the scolling of content | #GtkScrollbar |
+| `SEARCH_BOX` | A text box for entering search criteria | #GtkSearchEntry |
 | `SEPARATOR` | A divider that separates sections of content or groups of items | #GtkSeparator |
 | `SPIN_BUTTON` | A range control that allows seelcting among discrete choices | #GtkSpinButton |
 | `SWITCH` | A control that represents on/off values | #GtkSwitch |
index ca3a3f883d642aa3237d0e5180e0d089ae737d2d..c4d11cb95c6fa424180c9872ccb228c84ec95831 100644 (file)
@@ -1217,7 +1217,8 @@ typedef enum {
  *    of content within a viewing area, regardless of whether the content is fully
  *    displayed within the viewing area.
  * @GTK_ACCESSIBLE_ROLE_SEARCH: Unused
- * @GTK_ACCESSIBLE_ROLE_SEARCH_BOX: Unused
+ * @GTK_ACCESSIBLE_ROLE_SEARCH_BOX: A type of textbox intended for specifying
+ *    search criteria.
  * @GTK_ACCESSIBLE_ROLE_SECTION: Unused
  * @GTK_ACCESSIBLE_ROLE_SECTION_HEAD: Unused
  * @GTK_ACCESSIBLE_ROLE_SELECT: Unused
index ab94d0718c44914f3c3dba09a136152c967b879d..ece8cc0c28844086a74181db70cf588bee3aca77 100644 (file)
  *
  * GtkSearchEntry has a single CSS node with name entry that carries
  * a .sarch style class, and the text node is a child of that.
-
+ *
+ * # Accessibility
+ *
+ * GtkSearchEntry uses the #GTK_ACCESSIBLE_ROLE_SEARCH_BOX role.
  */
 
 enum {
@@ -177,14 +180,28 @@ gtk_search_entry_set_property (GObject      *object,
                                GParamSpec   *pspec)
 {
   GtkSearchEntry *entry = GTK_SEARCH_ENTRY (object);
+  const char *text;
 
   if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
-    return;
+    {
+      if (prop_id == NUM_PROPERTIES + GTK_EDITABLE_PROP_EDITABLE)
+        {
+          gtk_accessible_update_property (GTK_ACCESSIBLE (entry),
+                                          GTK_ACCESSIBLE_PROPERTY_READ_ONLY, !g_value_get_boolean (value),
+                                          -1);
+        }
+
+      return;
+    }
 
   switch (prop_id)
     {
     case PROP_PLACEHOLDER_TEXT:
-      gtk_text_set_placeholder_text (GTK_TEXT (entry->entry), g_value_get_string (value));
+      text = g_value_get_string (value);
+      gtk_text_set_placeholder_text (GTK_TEXT (entry->entry), text);
+      gtk_accessible_update_property (GTK_ACCESSIBLE (entry),
+                                      GTK_ACCESSIBLE_PROPERTY_PLACEHOLDER, text,
+                                      -1);
       break;
 
     case PROP_ACTIVATES_DEFAULT:
@@ -398,6 +415,7 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
 
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, I_("entry"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_SEARCH_BOX);
 }
 
 static GtkEditable *
index cd27dc80a267d857dae99068eb61e97737f1d973..8358d7b2c547c8711cf23d460c3588bd0a9d8f7f 100644 (file)
@@ -19,6 +19,7 @@ tests = [
   { 'name': 'label' },
   { 'name': 'progressbar' },
   { 'name': 'scrollbar' },
+  { 'name': 'searchentry' },
   { 'name': 'separator' },
   { 'name': 'spinbutton' },
   { 'name': 'switch' },
diff --git a/testsuite/a11y/searchentry.c b/testsuite/a11y/searchentry.c
new file mode 100644 (file)
index 0000000..4c44940
--- /dev/null
@@ -0,0 +1,41 @@
+#include <gtk/gtk.h>
+
+static void
+search_entry_role (void)
+{
+  GtkWidget *widget = gtk_search_entry_new ();
+  g_object_ref_sink (widget);
+
+  gtk_test_accessible_assert_role (widget, GTK_ACCESSIBLE_ROLE_SEARCH_BOX);
+
+  g_object_unref (widget);
+}
+
+static void
+search_entry_properties (void)
+{
+  GtkWidget *widget = gtk_search_entry_new ();
+  g_object_ref_sink (widget);
+
+  gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_PLACEHOLDER, NULL);
+  gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_READ_ONLY, FALSE);
+
+  g_object_set (widget, "placeholder-text", "Hello", NULL);
+  gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
+
+  gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_PLACEHOLDER, "Hello");
+  gtk_test_accessible_assert_property (widget, GTK_ACCESSIBLE_PROPERTY_READ_ONLY, TRUE);
+
+  g_object_unref (widget);
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/a11y/searchentry/role", search_entry_role);
+  g_test_add_func ("/a11y/searchentry/properties", search_entry_properties);
+
+  return g_test_run ();
+}